package 斗地主_控制台版;

import java.util.ArrayList;
import java.util.Collections;

public class PokerGame1 {
    //创建集合(牌盒)
    static ArrayList<String> list=new ArrayList<>();

    //使用静态代码块加载牌,
    //静态代码块特点:顺着类的加载而加载,只执行一次
    static{
        //创建两个集合用于存储号码和花色,进行遍历拼接到集合中
        String [] color={"♥","♣","♦","♠"};
        String [] number={"A","2","3","4","5","6","7","8","9","10","J","Q","K"};

        //遍历数组
        for (String s : color) {
            //s表示每一个花色
            for (String s1 : number) {
                //s1表示号码
                //进行拼接
                list.add(s+s1);
            }
        }
        list.add("大王");
        list.add("小王");
    }


    public PokerGame1() {
        System.out.println("打乱前"+list);
        //准备牌
        //洗牌(带乱集合)
        Collections.shuffle(list);
        System.out.println("打乱后"+list);
        //发牌
        /*创建集合用来发牌打牌3r＋底牌=4个集合对象*/
        ArrayList<String> daPai1=new ArrayList<>();
        ArrayList<String> daPai2=new ArrayList<>();
        ArrayList<String> daPai3=new ArrayList<>();
        ArrayList<String> underCard=new ArrayList<>();
        //遍历牌盒/发个每一个人
        for (int i = 0; i < list.size(); i++) {
            //i表示索引,普通for可以更好的计算牌应该发个谁
            String poker = list.get(i);
            if (i<3){
                underCard.add(poker);
                continue;
            }
            if (i%3==0){
                daPai1.add(poker);
            }else if (i%3==1){
                daPai2.add(poker);
            }else {
                daPai3.add(poker);
            }
            }
        System.out.println(daPai1);
        System.out.println(daPai2);
        System.out.println(daPai3);
        System.out.println(underCard);
        }
    }

